// pages/login/login_in.js
let app = getApp();
let network = require('../../utils/requestManager.js');
let md5 = require('../../utils/md5.min.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    win_height: '',
    login_id:null,
    login_password:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      win_height: app.globalData.winHeight
    })
  },

  //获取账号
  bind_id:function(e){
    console.log(e)
    let that = this;
    that.setData({
      login_id: e.detail.value
    })
  },

  //获取密码
  bind_password: function (e) {
    console.log(e)
    let that = this;
    that.setData({
      login_password: e.detail.value
    })
  },

  //账号密码登录
  login_btn:function(){
    let that = this;
    // console.log(that.data.login_password);
    // console.log(md5(that.data.login_password));
    wx.request({
      method: 'POST',
      url: 'https://shop.hbsse.com/backend/shop/v1/admin/api/seller/login',
      data: {
        phone: that.data.login_id,
        password: md5(that.data.login_password)
      },
      header: {
        'Content-type': 'application/json; charset=UTF-8',
        // 'Authorization': 'Token ' + app.globalData.token,
        // 'version': version
      },
      success: function (res) {
        console.log(res.data)
        console.log(' 请求成功')
        setTimeout(function () {
          wx.stopPullDownRefresh()
        }, 100)
        wx.hideLoading()
        if (res.data.status == 0) {
          console.log("成功");
          app.globalData.token = res.data.detail;
          app.globalData.owner = res.data.identity;
          wx.navigateTo({
            url: '/pages/index/index',
          });
        } else {
          console.log("失败");
          app.globalData.token = '';
          wx.showModal({
            title: '提示',
            content: res.data.detail,
          })
        }
      },
      fail: function (res) {
        console.log(interfaceStr + ' 请求失败')
        setTimeout(function () {
          wx.stopPullDownRefresh()
        }, 100)
        console.log(res)
      }
    })
  },

  // 微信登录
  login_wx: function (){
    console.log('wx login');
    network.login();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})